$(function () {
  initDatasource();
});

function initDatasource() {
    var datasource = $("#datasourceData").data("datasourceData");
    if(!datasource){
        return ;
    }
    $.ajax({
        url: "/datasource/get",
        contentType: 'application/json',
        data: JSON.stringify(datasource),
        method: "post",
        success: function (response) {
            var data = response;
            $("#datasource").deserializable(data);
            $("#datasourceAttribute").deserializable(data.attribute);
        }
    });

}

function saveDataSource() {
   var datasource =  $("#datasource").serializable();
    datasource.attribute = $("#datasourceAttribute").serializable();
    $.ajax({
        url: "/datasource/add",
        contentType: 'application/json',
        data: JSON.stringify(datasource),
        method: "post",
        dataType: "json",
        success: function (response) {

        }
    });
}